<?php
require_once("include/config.php");

class CompetitionPage extends CommonPage {
	
	public function __construct() {
		parent::__construct();
		$this->header = new Header("competition");
		$this->setTitle(Lng::COMPETITIONS);
		$this->clearStyleSheet();
		$this->addStyleSheet("competition.css");
		$this->rightColumn->clean();
		$this->addRightColumn(new CompetitionSubMenu());
		switch(Page::get("action")) {
			case "":
				$this->addContent(new CompetitionIntroduction());
				$res = Discussion::readByMoreTopics(Competition::getTopicsID(),0,Page::get("page"));
				while ($comp = mysql_fetch_object($res)) {
					$this->addContent(new CompetitionInfo($comp));
				}
				break;
			case "formCompetition":
				$this->addContent(new FormCompetition(Page::get("follow")));
				break;
			case "readOne":
				if (Page::get("follow")) {
					$res = Discussion::read(Page::get("topic"),Page::get("follow"),Page::get("page"),"follow, date DESC");
					$comp = mysql_fetch_object($res);
					$this->addContent(new CompetitionInfo($comp));
					$this->addContent(new H(3,new String(Lng::COMPETITION_DISCUSSION)));
					while($dis = mysql_fetch_object($res)) {
						$this->addContent(new DiscussionInfo($dis));
					}
					$this->addContent(new FormDiscussion());
				}
				$this->addContent(new Paging(__FILE__));
				break;
			case "competitionDestroy":
				Discussion::destroy(Page::get("discussion"));
				if (Page::get("discussion") != Page::get("follow")) {
					Header("competition.php?action=readOne&follow=".Page::get("follow")."&topic=".Page::get("topic"));
				}
				else {
					Header("competition.php?action=category&topic=".Page::get("topic"));
				}
				break;
			case "category":
				if (Page::get("topic")) {
					$res = Discussion::read(Page::get("topic"),0,Page::get("page"));
					while ($comp = mysql_fetch_object($res)) {
						$this->addContent(new CompetitionInfo($comp));
					}
				}
				$this->addContent(new Paging(__FILE__));
				break;
		}
	}
}
$page = new CompetitionPage();
$page->view();
?>